#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
const int N = 1e5 + 10;
int a[N], b[N];
int c[N], d[N];
int x, y, n;
int cnt1, cnt2;
struct node1
{
	int a, b;
}S1[N];
struct node2
{
	int a, b;
}S2[N];
int cmp1(node1 a, node1 b)
{
	if (a.a != b.a)return a.a < b.a;
	else return a.b > b.b;
}
int cmp2(node2 a, node2 b)
{
	if (a.a != b.a)return a.a < b.a;
	else return a.b > b.b;
}
int main()
{
	cin >> n >> x >> y;
	for (int i = 1; i <= n; i++) {
		string op;
		int v1, v2;
		cin >> op >> v1 >> v2;
		if (op[0] == 'A') {
			S1[++cnt1] = { v1,v2 };
		}
		else {
			S2[++cnt2] = { v1,v2 };
		}
	}
	if (cnt1 < x || cnt2 < y) {
		cout << -1 << endl;
		return 0;
	}
	sort(S1 + 1, S1 + cnt1 + 1, cmp1);
	sort(S2 + 1, S2 + cnt1 + 1, cmp1);
	int ans = 0;
	for (int i = 1; i <= x; i++) {
		ans += S1[i].b;
	}
	for (int i = 1; i <= y; i++) {
		ans += S2[i].b;
	}
	cout << ans << endl;
	return 0;
}